import scala.io.Source
import scala.collection.mutable.Map

object PopularTeacher {
  def main(args: Array[String]): Unit = {
    val logPath = "E:\\JSPproject\\Scallahomework\\src\\main\\scala\\teacher.log"

    val tc: Map[String, Int] = Map().withDefaultValue(0)

    val lines = Source.fromFile(logPath).getLines()

    for (line <- lines) {
      val name = line.split("/").last
      tc(name) += 1
    }

    val maxCount = tc.values.max
    val popular = tc.filter { case (_, count) => count == maxCount }

    println("所有老师的访问次数:")
    tc.foreach { case (name, count) =>
      println(s"($name, $count)")
    }

    println("\n最受欢迎的老师及访问次数:")
    popular.foreach { case (name, count) =>
      println(s"($name, $count)")
    }
  }
}